const mongoose = require("mongoose");

const userSchema = new mongoose.Schema({
    username: {
        type: String,
        required: [true, "用户名是必需的"],
        unique: true,
        trim: true,
        minlength: [3, "用户名至少需要3个字符"],
    },
    email: {
        type: String,
        required: [true, "邮箱是必需的"],
        unique: true,
        trim: true,
        lowercase: true,
        match: [/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/, "请输入有效的邮箱地址"],
    },
    password: {
        type: String,
        required: [true, "密码是必需的"],
        minlength: [6, "密码至少需要6个字符"],
    },
    createdAt: {
        type: Date,
        default: Date.now,
    },
});

module.exports = mongoose.model("User", userSchema);
